package uk.co.AndVCardUtils.ContactSender;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
import uk.co.AndVCardUtils.ContactSender.R; 

public class SourceContactList extends ListActivity {

	private ListAdapter mAdapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.);
		
		Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
		startManagingCursor(c);
	        
		String[] columns = new String[] {People.NAME};
		int[] names = new int[] {R.id.row_entry};
	        
		mAdapter = new SimpleCursorAdapter(this, R.layout.main, c, columns, names);
		setListAdapter(mAdapter);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		Context ctx = getApplicationContext();
		Intent i = new Intent(ctx, DestinationContactList.class);
		
		Cursor c = (Cursor) mAdapter.getItem(position);
		String name = c.getString(c.getColumnIndex(People.DISPLAY_NAME));
		
		Toast.makeText(this, name + " selected", Toast.LENGTH_LONG).show();
		
		//i.setData(Uri.withAppendedPath(Phones.CONTENT_URI, phoneId));
		startActivity(i);
	}

}